<?php
/* SVN FILE: $Id: transferCache.php 260 2010-01-21 22:38:54Z supersmashbrothers $ */
/**
* ibMarket 2
* IP.Board 3.0
* ibMarket Cache functions
* ibMarket IPB cache functions
*
* @author $Author: supersmashbrothers $
* @copyright $Copyright$
* @version $Revision: 260 $
* @lastrevision $Date: 2010-01-21 22:38:54 +0000 (Thu, 21 Jan 2010) $
* @modifiedby $LastChangedBy: supersmashbrothers $
* @lastmodified $LastChangedDate: 2010-01-21 22:38:54 +0000 (Thu, 21 Jan 2010) $
* @filesource $URL: http://ipb-ibmarket.googlecode.com/svn/ibmarket2/trunk/admin/applications_addon/other/ibmarket/plugins/transfer/transferCache.php $
*/

final class transferCache
{
	/**#@+
	 * Registry Object Shortcuts
	 *
	 * @access	protected
	 * @var		object
	 */
	protected $registry;
	protected $DB;
	protected $settings;
	protected $request;
	protected $lang;
	protected $member;
	protected $memberData;
	protected $cache;
	protected $caches;
	/**#@-*/
	
	/**
	 * Make the registry shortcuts
	 *
	 * @access	public
	 * @param	object	ipsRegistry reference
	 * @return	void
	 */
	public function makeRegistryShortcuts( ipsRegistry $registry )
	{
		/* Make registry objects */
		$this->registry   =  $registry;
		$this->DB         =  $this->registry->DB();
		$this->settings   =& $this->registry->fetchSettings();
		$this->request    =& $this->registry->fetchRequest();
		$this->lang       =  $this->registry->getClass('class_localization');
		$this->member     =  $this->registry->member();
		$this->memberData =& $this->registry->member()->fetchMemberData();
		$this->cache      =  $this->registry->cache();
		$this->caches     =& $this->registry->cache()->fetchCaches();
	}
	
	/**
	 * Rebuilds Transfer permissions cache
	 *
	 * @access	public
	 * @return	void
	 */
	public function cachePermissions()
	{
		$perm = array(0 => 'deny', 1 => 'allow');
		$cache = array();
		$cache['deny'] = array();
		$cache['allow'] = array();
		
		$this->DB->build(array('select'=>'*','from'=>'market_transfer_permissions'));
		$this->DB->execute();
		while($permission = $this->DB->fetch())
		{
			if(strpos($permission['p_option'],'item') === 0)
			{
				$item = explode('-',$permission['p_option']);
				$cache[$perm[$permission['allowed']]][$permission['group_id']][$item[0]][$item[1]] = $permission;
			}
			else
			{
				$cache[$perm[$permission['allowed']]][$permission['group_id']][$permission['p_option']] = $permission;
			}
		}
		
		$this->cache->setCache( 'ibm_transfer_perm', $cache, array( 'array' => 1, 'deletefirst' => 1, 'donow' => 0 ) );
	}
	
	/**
	 * Rebuilds Transfer fees cache
	 *
	 * @access	public
	 * @return	void
	 */
	public function cacheFees()
	{
		$cache = array();
		
		$this->DB->build(array('select'=>'*','from'=>'market_transfer_fees'));
		$this->DB->execute();
		while($fee = $this->DB->fetch())
		{
			if(strpos($fee['fee_type'],'item') === 0)
			{
				$item = explode('-',$fee['fee_type']);
				$cache[$fee['group_id']][$item[0]][$item[1]][] = $fee;
			}
			else
			{
				$cache[$fee['group_id']][$fee['fee_type']][] = $fee;
			}
		}
		
		$this->cache->setCache( 'ibm_transfer_fees', $cache, array( 'array' => 1, 'deletefirst' => 1, 'donow' => 0 ) );
	}
}
?>